import numpy as np

# 创建一个示例数组
data = np.array([[5.1, 3.5, 1.4, 0.2],
                  [4.9, 3.0, 1.4, 0.2],
                  [4.7, 3.2, 1.3, 0.2],
                  [4.6, 3.1, 1.5, 0.2]])
# 沿着纵轴排序
data.sort(axis=0)
print("沿axis=0排序后：\n", data)
# 沿着横轴排序
data.sort(axis=1)
print("沿axis=1排序后：\n", data)

# 定义结构化数组
dype = [('name', 'S10'), ('age',int)]
data = np.array([("Alice", 30), ("Bob", 25), ("Cathy", 45), ("Dave", 35)], dtype = dype)
# 根据年龄排序
age_sorted = np.sort(data, order='age')
print("根据年龄排序后：\n", age_sorted)
